package java8.atguigu.teacher.lambda03;

import java8.atguigu.lu.l01.Employee;
import org.junit.Test;

import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/**
 * @program lambda
 * @description:
 * @author: zhanglu
 * @create: 2019-05-26 20:25:00
 */
public class TestLambda {

    List<Employee> employeeList = Arrays.asList(
            new Employee("张1",20,100),
            new Employee("张2", 21, 101),
            new Employee("张3", 22, 102),
            new Employee("张4", 23, 103),
            new Employee("张5", 24, 104),
            new Employee("张6", 25, 105)
    );

    @Test
    public void test01(){
        Collections.sort(employeeList, new Comparator<Employee>() {
            @Override
            public int compare(Employee o1, Employee o2) {
                return o2.getAge() - o1.getAge();
            }
        });
        employeeList.stream().forEach(System.out::println);
    }


    @Test
    public void test02(){
        System.out.println(strHandle("\t\t\t 我的世界 ", str -> str.trim()));

        System.out.println(strHandle("adhba", str -> str.toUpperCase()));
    }
    //处理字符串
    public String strHandle(String str, MyFunction mf){
        return mf.getValue(str);
    }

    @Test
    public void test03(){
        System.out.println(longHandle(100, 200, (x, y) -> x + y));
        System.out.println(longHandle(23, 34, (x, y) -> x * y));
    }

    //对于两个long 型数据进行处理
    public long longHandle(long l1, long l2, MyFunction01<Long, Long> mf){
        return mf.getValue(l1, l2);
    }

}
